package vy.org.app.common;

import java.security.KeyException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.vy.dal.dao.VyMagazineSubscriptionDO;
import org.vy.dal.seq.SubscriptionSeqGenerator;

public class SubscriptionIdGenerator {
	private static SimpleDateFormat DATE_FMT = new SimpleDateFormat("MMddyyyy");
	
	public static String generateId(VyMagazineSubscriptionDO subDO, Date receitDate, String country, String stateOrRegion) throws KeyException{

		if(receitDate == null)
			receitDate = new Date();
		if(receitDate == null || country == null || stateOrRegion == null)
			throw new KeyException("Required information is missing to generate key");

		String id = SubscriptionSeqGenerator.getInstance().getNextSequence();

		id += "/" + DATE_FMT.format(receitDate) 
			+ "/" + country 
			+ "/" + stateOrRegion;
		return id;
	}
}
